import { fetchGoodList } from '@/api'

export default {
    namespaced: true,
    state: {
        cache: {}
    },
    mutations: {
        updataCache(state, payload) {
            // idx 从views中来
            // list 从后端来
            const { idx, list } = payload
            state.cache[idx] = list
            // 强制深复制一次
            state.cache = JSON.parse(JSON.stringify(state.cache))
        },
        cleanCache(state) {
            state.cache = {}
        }
    },
    actions: {
        getGoodslist(store, payload) {
            // idx,cate 来自view
            const { idx, cate } = payload
            fetchGoodList({ cate }).then(res => {
                store.commit('updataCache', { idx, list: res.list })
            })
        }
    }
}